<?php

namespace C\P;

use C\P\Http;
use C\L\Logs;

const EVENT_CODE = [
    'activate' => '0',
    'register' => '1',
];

class Aiclk
{
    private $logger;

    public function __construct()
    {
        $this->logger = (new Logs)->set('aiclk_' . date('Ymd') . '.log');
    }

    /**
     * @param string $callbackUrl
     * @param int $event
     */
    public function report($callbackUrl, $event)
    {
        $logInfo = [
            'callback_url' => $callbackUrl,
            'event'        => $event,
        ];
        $this->logger->notice(json_encode($logInfo));

        $eventCode = EVENT_CODE[$event] ?? -1;

        $url = $callbackUrl . '&op2=' . $eventCode;

        $rawResponse = Http::get($url, [], 10);

        $this->logger->notice(json_encode($rawResponse));

        return true;
    }
}
